﻿using SSCAI.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace SSCAI.Client.Models
{
    public sealed class LotteryData
    {
        private static LotteryData instance;
        private static object syncLock = new object();
        private List<LotteryModel> lotterys; 

        private LotteryData()
        {          
            var loDatas = XmlHelper.GetXmlItems();
            var index = loDatas.Count();
            this.lotterys = loDatas.Select(d => new LotteryModel
            {
                Id = index--,
                Issue = d.Attribute("issue").Value,
                WinningNumber = d.Attribute("lottery").Value,
                ModifiedTime = d.Attribute("time").Value

            }).ToList();
        }

        public List<LotteryModel> Lotterys
        {
            get
            {
                return this.lotterys;
            }
        }

        public static LotteryData GetInstance()
        {
            if (instance == null)
            {
                lock (syncLock)
                {
                    if (instance == null)
                    {
                        instance = new LotteryData();
                    }
                }
            }

            return instance;
        }

        public static void ClearInstance()
        {
            instance = null;
        }

    }
}
